import request from '@/utils/request.js'
import {postByContentTypeFormUrlencoded} from "@/utils/http.js"
import {encryptByRSACommonPublicKey} from "@/utils/encrypt_utils.js"

/**
 * 通过输入的邮箱获取邮箱验证码
 *
 * @param mail 用户输入的邮箱
 * @return {Promise<axios.AxiosResponse<any>>}
 */
export function getMailCodeAPI(mail) {
    return postByContentTypeFormUrlencoded(
        '/login/mail/code',
        {
            // 对用户输入的邮箱进行 RSA 加密
            mail: encryptByRSACommonPublicKey(mail)
        }
    )
}

export function loginByMailAPI(mail, code) {
    return request.post(
        '/login/mail',
        {
            mail: encryptByRSACommonPublicKey(mail),
            code: encryptByRSACommonPublicKey(code)
        }
    )
}